EditEmployeeController = function() {

    var user=sessionStorageClient.getJSON("user");
	
	this.editEmployee = function(employeeId) {
		
		var tempParamData = CommonUtil.takeOutParamObject();
		if (tempParamData && tempParamData != null) {
			var employeeName = $("#editEmployeePage #employeeName").val();
			var employeeMobile = $("#editEmployeePage #employeeMobile").val();
			var employeeCode = $("#editEmployeePage #employeeCode").val();
			var employeeLevel = $("#editEmployeePage #employeeLevel").attr("data-employeeLevelId");
			var affiliation =user.role==4?"2":$("#editEmployeePage #affiliation").attr("data-affiliationId");
			var onjobStatus = $("#editEmployeePage #onjobStatus").attr("data-onjobStatusId");
			//var $shopId = $("#shopId");
			var shopId =user.role==4?user.selfShopId:$("#editEmployeePage #shopId").attr("data-shopId");
			//var shopId = employeeStoreListFilterParam.shopId;
			if(employeeName == ""){
				DialogUtil.dialogWarn("请填写员工姓名");
				return;
			}
			if(employeeName.length > 10){
				DialogUtil.dialogWarn("员工姓名不能超过10个字");
				return;
			}
			if(employeeCode.length > 20){
				DialogUtil.dialogWarn("员工编号不能超过20个字");
				return;
			}
			var  checkNameReg = /^[\u4e00-\u9fffa-zA-Z0-9]+$/;
			if(checkNameReg && !checkNameReg.test(employeeName)){
				DialogUtil.dialogWarn("员工姓名不允许输入特殊字符");
				return;
			}

			if(onjobStatus==""){
				DialogUtil.dialogWarn("请填写在职状态");
				return;
			}
			if(affiliation ==undefined) {
				DialogUtil.dialogWarn("请选择所属编制");
				return;
			}
			if(affiliation == "2" && shopId == "") {
				DialogUtil.dialogWarn("请选择所属门店");
				return;
			}
			if(employeeLevel==""){
				DialogUtil.dialogWarn("请选择员工角色");
				return;
			}
			common.loading("请稍候...");
		
			var postData = {
				shopId : shopId,
				employeeLevel:employeeLevel,
				employeeName : employeeName,
				employeeCode : employeeCode,
				affiliation : affiliation,
				employeeMobile : employeeMobile,
				onjobStatus : onjobStatus,
				employeeId : employeeId
			};
           
			var serverUrl = App.serverUrl + "app/employee/update.do";
			var sucFunc = function(result) {
				if (result.success) {
					employeeManageParams.isSucFlag=true;
					employeeManageParams.handleBack4StoreManage = "load";
					var serverResult = result.resultObject;
					if (serverResult.success) {
						DialogUtil.dialogWarn("修改员工成功!", function() {
							if (serverResult && serverResult!=null) {
								$.router.load("employee_manage.html");
							} else {
								DialogUtil.dialogWarn("修改员工异常!");
							}
						});
					} else {
						DialogUtil.dialogWarn(serverResult.msg);
					}
				} else {
					DialogUtil.dialogWarn();
				}
				common.closeLoading();
			};
			AppUtil.call(AppUtil.APIS.SEND_HTTP_REQUEST,
				{
					type: "POST",
					url: serverUrl,
					data: JSON.stringify(postData)
				}, sucFunc);
			
		} else {
			DialogUtil.dialogWarn("数据异常,编辑员工!");
			return false;
		}
	};
// 获取用户详情
	this.getEmployee = function(employeeId) {
		var serverUrl = App.serverUrl +　"/app/employee/info.do?employeeId="+employeeId;
		var sucFunc = function (result) {
			if (result && result.success) {
				// 服务器返回成功
				var employee = result.resultObject;
				// 格式化后端数据
				employee.userRole=user.role;
				CommonUtil.render($("#editEmployeePage .page-body #userEditContainer"), "userEditTPL", employee);
               
					var rg_data = [{
						text: "总部",
						value: 1
					}, {
						text: "单门店",
						value: 2
					},
					];
					var er_data = [];
					if(employee.affiliationName=="单门店"){
						if(employee.userRole!=4){
					    er_data = [
							 {
								text: "店长",
								value: 4
							},
							{
								text: "服务员",
								value: 5
							}, {
								text: "收银员",
								value: 6
							}
							];
						}else{
						 er_data = [
							
							{
								text: "服务员",
								value: 5
							}, {
								text: "收银员",
								value: 6
							}
							];	
						}
					}else{
					er_data=[{
						text: "运营/市场",
						value: 2
					}, {
						text: "财务",
						value: 3
					},
					];
					}
		//	$('#editEmployeePage #rganization').mobiscroll().select({
		//			theme: 'ios',
		//			display: 'bottom',
		//			lang: 'zh',
		//			placeholder: '请选择',
		//			defaultValue:'总部',
	//				data: rg_data,
		//			onSelect: function (valueText, inst) {
		//				$(this).siblings("input[type=hidden]").val(inst._tempValue);
		//				$("#editEmployeePage #affiliation").attr("data-affiliationId",inst._tempValue);
		//				if (valueText === "单门店") {
		//					$("#employeeLevel").attr("data-employeeLevelId",4);
		//					$("#editEmployeePage .showShop").removeClass("hide");
	//						er_data = [{
		//						text: "店长",
		//						value: 4
		//					}, {
		//						text: "服务员",
		//						value: 5
		//					}, {
		//						text: "收银员",
		//						value: 6
		//					}
		//					];
		//					er.option({data: er_data});
		//					er.refresh();
		//				} else if (valueText === "总部") {
		//					$("#editEmployeePage #employeeLevel").attr("data-employeeLevelId",2);
		//					$("#editEmployeePage .showShop").addClass('hide');
		//					er_data = [{
		//						text: "运营/市场",
		//					value: 2
		//					}, {
		//						text: "财务",
		//						value: 3
		//					},
		//					];
		//					er.option({data: er_data});
		//					er.refresh();
		//				}
		//				er_data.forEach(function(val){
		//					if(val.text===er._tempValue){
		//						$('#editEmployeePage #employeeLevel').val(val.value);
			//				}
		//				})
		//			},
		//			onInit: function (event, inst) {
		//				if (employee.affiliationName === "单门店") {
		//					er_data = [{
		//						text: "店长",
		//						value: 4
		//					}, {
		//						text: "服务员",
		//						value: 5
		//					}, {
		//						text: "收银员",
		//						value: 6
		//					}
		//					];
		//				} else if (employee.affiliationName === "总部") {
		//					er_data = [{
		//						text: "运营/市场",
		//						value: 2
		//					}, {
		//						text: "财务",
		//						value: 3
		//					},
		//					];
		//				}
		//			},
			//	});

			//	$('#editEmployeePage #rganization').prev("input").val(employee.affiliationName);
				var er;


				$('#editEmployeePage #employee-role').mobiscroll().select({
					theme: 'ios',
					display: 'bottom',
					lang: 'zh',
					data: er_data,
					placeholder: '请选择',
					onInit: function (event, inst) {
						er = event;
					},
					onSelect: function (valueText, inst) {

						$(this).siblings("input[type=hidden]").val(inst._tempValue);
						$("#editEmployeePage #employeeLevel").attr("data-employeeLevelId",inst._tempValue);
					}
				});
				$('#editEmployeePage #employee-role').prev("input").val(employee.roleName);


					var ws_data = [{
						text: "在职",
						value: 1
					}, {
						text: "离职",
						value: 2
					},
					];
					$('#editEmployeePage #work-status').mobiscroll().select({
						theme: 'ios',
						display: 'bottom',
						lang: 'zh',
						data: ws_data,
						placeholder: '请选择',
						onSelect: function (valueText, inst) {

							$(this).siblings("input[type=hidden]").val(inst._tempValue);
							$("#editEmployeePage #onjobStatus").attr("data-onjobStatusId",inst._tempValue);
						}
					});
				$('#editEmployeePage #work-status').prev("input").val(employee.onjobStatus == '2'?"离职":"在职");
			} else {
				DialogUtil.dialogWarn(result.msg);
			}
		}
		CommonUtil.sendJsonpRequest({
			url: serverUrl,
			success: sucFunc
		});

	};
};